<template>
	<view class="index">
		<view class="bg"></view>
		<view class="top-wrapper">
			<view class="status_bar">
				<!-- 这里是状态栏 -->
			</view>
			<view class="title-wrapper">
				<text class="title">{{ userInfo.nickName }}@银川总仓</text>
				<text v-if="environment === 'D'" class="version">(测试环境)</text>
				<text v-if="environment === 'T'" class="version">(体验环境)</text>
				<view class="logout" @click="openMenu">
					<uni-icons type="bars" class="icon" size="26" color="#ffffff"></uni-icons>
				</view>
			</view>
			<!-- <view class="user-info" @click="goPage('/subPage_mine/index')">
				<image class="logo" src="../../static/image/user-logo.png" mode="widthFix"></image>
				<view class="info-wrapper">
					<view class="nickname">
						小牛牛
					</view>
					<view class="store-name">
						牛老二蔬菜批发
					</view>
				</view>
				<uni-icons type="right" color="#ffffff" size="24"></uni-icons>
			</view> -->
			<!-- <view class="notice-wrappers">
				<cc-noticeBar :noticeList="noticeList" @click="itemClick" @goMore="goMore"></cc-noticeBar>
			</view> -->
		</view>
		<mescroll-uni height="100%" bottom="130" @init="mescrollInit" @down="refresh" :up="upOption" :down="downOption">
			<view class="schedule-box">
				<view class="schedule-bg-box"></view>
				<view class="schedule-content-box">
					<view class="schedule-wrapper">
						<view class="item" @click="goPage('/subPage_supplier/index','app:supplier:list')">
							<view class="number">{{ countStatistics.supplier || 0 }}</view>
							<view class="label">
								供应商
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_supplier/index?type=2','app:supplier:list')">
							<view class="number">{{ countStatistics.supplier_enter || 0 }}</view>
							<view class="label">
								入驻审核
							</view>
						</view>
						<view class="item"
							@click="goPage('/subPage_product/productManagement?type=2','app:product:examine')">
							<view class="number">{{ countStatistics.on_shelf || 0 }}</view>
							<view class="label">
								上架审核
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_quotation/index?type=1','app:price:examine')">
							<view class="number">{{ countStatistics.price || 0 }}</view>
							<view class="label">
								报价审核
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_product/productManagement','app:product:list')">
							<view class="number">{{ countStatistics.on_sale || 0 }}</view>
							<view class="label">
								在售商品
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_distribution/index','app:transpot:dispatch')">
							<view class="number">{{ countStatistics.dispatch || 0 }}</view>
							<view class="label">
								待调车
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_supply/index','app:supply-order:list')">
							<view class="number">{{ countStatistics.pending || 0 }}</view>
							<view class="label">
								待交货
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_transport/index','app:transport:list')">
							<view class="number">{{ countStatistics.depart || 0 }}</view>
							<view class="label">
								待发车
							</view>
						</view>
					</view>
					<view class="notice-wrapper">
						<cc-noticeBar colors="#575A6E" :noticeList="noticeList" @click="itemClick"
							@goMore="goMore"></cc-noticeBar>
					</view>
				</view>
			</view>

			<view class="content-wrapper">
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							供应商
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="newSupply">
							<image src="../../static/image/new-supply.png" class="icon" mode="widthFix"></image>
							<view class="label">
								供应商入驻
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_supplier/index','app:supplier:list')">
							<image src="../../static/image/supply.png" class="icon" mode="widthFix"></image>
							<view class="label">
								供应商
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_product/productManagement','app:product:list')">
							<image src="../../static/image/product-management.png" class="icon" mode="widthFix"></image>
							<view class="label">
								商品管理
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_quotation/index','app:prices:list')">
							<image src="../../static/image/quote.png" class="icon" mode="widthFix"></image>
							<view class="label">
								报价报量
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_supply/index','app:supply-order:list')">
							<image src="../../static/image/delivery.png" class="icon" mode="widthFix"></image>
							<view class="label">
								供货管理
							</view>
						</view>



						<!-- <view class="item">
						<image src="../../static/logo.png" class="icon" mode="widthFix"></image>
						<view class="label">
							客户评价
						</view>
					</view> -->
					</view>
				</view>
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							品控
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="goPage('/subPage_testing/index','app:rejects:list')">
							<image src="../../static/image/quality.png" class="icon" mode="widthFix"></image>
							<view class="label">
								质检管理
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_receiptOrder/index','app:shipment:list')">
							<image src="../../static/image/delivery-receipt.png" class="icon" mode="widthFix"></image>
							<view class="label">
								交货回单
							</view>
						</view>
					</view>
				</view>
				<view class="function-wrapper">
					<view class="title-wrapper">
						<view class="title">
							物流
						</view>
					</view>
					<view class="item-wrapper">
						<view class="item" @click="goPage('/subPage_distribution/index','app:transpot:dispatch')">
							<image src="../../static/image/scheduling.png" class="icon" mode="widthFix"></image>
							<view class="label">
								车辆调度
							</view>
						</view>
						<!-- <view class="item" @click="goPage('/subPage_receiptOrder/index','app:shipment:list')">
							<image src="../../static/image/delivery-receipt.png" class="icon" mode="widthFix"></image>
							<view class="label">
								交货回单
							</view>
						</view> -->
						<view class="item" @click="goPage('/subPage_transport/index','app:transport:list')">
							<image src="../../static/image/transport.png" class="icon" mode="widthFix"></image>
							<view class="label">
								发车管理
							</view>
						</view>
						<view class="item"
							@click="goPage('/subPage_entrucking/supplyManagement','app:entrucking:list')">
							<image src="https://cdpresources.hobon.cc/city-warehouse-app/static/productManage.png"
								class="icon" mode="widthFix"></image>
							<view class="label">
								装车统计
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_vehicle/index','app:vehicle:list')">
							<image src="../../static/image/vehlie.png" class="icon" mode="widthFix"></image>
							<view class="label">
								车辆管理
							</view>
						</view>
						<view class="item" @click="goPage('/subPage_loader/index','app:loader:list')">
							<image src="../../static/image/loader.png" class="icon" mode="widthFix"></image>
							<view class="label">
								装车工管理
							</view>
						</view>
					</view>
				</view>

				<view class="time-info">
					<view class="title">
						<text class="text">银川总仓运营时间点：</text>
						<view class="line"></view>
					</view>
					<view class="info" v-for="(item,index) in supplyWarehouseInfo.schemaList" :key="index">
						<text>{{ item.caption }}：{{ dateFormat(item) }}</text>
						<text>交货：{{ item.stopTime }}~{{ item.stopReceiveTime }}</text>
					</view>
					<view class="info">
						<text>报价：{{ supplyWarehouseInfo.deadlineOrders }}~{{ supplyWarehouseInfo.openingTime }}</text>
					</view>
				</view>

				<!-- <image src="../../static/image/sjx-logo.png" class="sjx-logo" mode="widthFix"></image> -->
			</view>

		</mescroll-uni>

		<uni-popup ref="popup">
			<view class="popup-wrapper">
				<view class="popup-title-wrapper">
					<text class="title">请选择</text>
					<uni-icons type="close" @tap="closeSupply" class="close" size="30" color="#888888"></uni-icons>
				</view>
				<view class="popup-content-wrapper">
					<view class="popup-item" @click="goPage('/subPage_supplier/register/index')">
						帮助供应商上传资料，完成入驻
					</view>
					<view class="popup-item" @click="goPage('/subPage_supplier/register/registerForSelf')">
						开通主账号，让供应商自助入驻
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import APPUpdate from '@/uni_modules/zhouWei-APPUpdate/js_sdk/appUpdate';
	import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
	export default {
		mixins: [MescrollMixin], // 使用mixin
		data() {
			return {
				environment: uni.getStorageSync('environment'),
				downOption: {
					auto: true, // 不自动加载 (mixin已处理第一个tab触发downCallback)
					textColor: "#ffffff"
				},
				upOption: {
					use: false,
					isLock: true
				},
				pageNum: 1,
				pageSize: 10,
				noticeList: [],
				countStatistics: {},
			}
		},
		onLoad() {
			this.getNotice()
			console.log("userInfo", this.userInfo)
		},
		onShow() {
			this.getCount()
			APPUpdate();
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo
			},
			supplyWarehouseInfo() {
				return this.$store.state.userInfo.supplyWarehouseInfo
			},
			//截单时间
			deadlineOrders() {
				return this.supplyWarehouseInfo.deadlineOrders.split(":")[0]
			},
			//开市时间
			openingTime() {
				return this.supplyWarehouseInfo.openingTime.split(":")[0]
			},
			//截止交货时间
			deadlineReceiving() {
				return this.supplyWarehouseInfo.deadlineReceiving.split(":")[0]
			},
		},
		methods: {
			dateFormat(item) {
				let str = "";
				let startTime = parseInt(item.startTime.split(":")[0])
				let endTime = parseInt(item.stopTime.split(":")[0])

				if (this.deadlineOrders < startTime) {
					str = "昨天" + item.startTime
				} else if (this.deadlineOrders >= startTime) {
					str = "今天" + item.startTime
				}
				str += '~'
				if (this.deadlineOrders < endTime) {
					str += "昨天" + item.stopTime
				} else if (this.deadlineOrders >= endTime) {
					str += "今天" + item.stopTime
				}
				return str
			},
			goPage(url, code) {
				if (code && !this.$permissions.verify(code)) {
					this.$showModal({
						title: '提示',
						content: '您没有权限访问',
						showCancel: false,
						confirmText: '确定'
					})
					return
				}
				uni.navigateTo({
					url: url
				})
				this.closeSupply()
			},
			async getNotice() {
				const data = await this.$api.post('/adm/notice/page', {
					noticeType: 3,
					pageNum: 1,
					pageSize: 10,
					orders: [{
						"asc": false,
						"column": "noticeId"
					}],
				})
				if (data.code === 200) {
					this.noticeList = data.data.records.map(item => {
						return {
							id: item.noticeId,
							title: item.noticeTitle
						}
					});
				}
			},
			async getCount() {
				const data = await this.$api.get('/adm/supplywarehouse/todoCount', {
					supplyWarehouseId: this.userInfo.supplyWarehouseId
				}, false)
				if (data.code === 200) {
					this.countStatistics = data.data;
				}
			},
			refresh() {
				this.getCount()
				this.mescroll.endSuccess(1, false)
			},
			newSupply() {
				if (!this.$permissions.verify('app:supplier:register')) {
					this.$showModal({
						title: '提示',
						content: '您没有权限访问',
						showCancel: false,
						confirmText: '确定'
					})
					return
				}
				this.$refs.popup.open('center')
			},
			closeSupply() {
				this.$refs.popup.close()
			},
			close() {
				this.$message.close()
			},
			logout() {
				this.$showModal({
					title: '温馨提示',
					content: '确定要退出登录吗？',
					confirmText: '退出',
					cancelText: '手滑了',
					success: (res) => {
						if (res.confirm) {
							this.$store.commit('setToken', '')
							uni.reLaunch({
								url: '/pages/login/index'
							})
						}
					}
				})
			},
			test() {},
			openMenu() {
				uni.showActionSheet({
					itemList: ['退出登录', '修改密码', '个人信息'],
					success: (e) => {
						if (e.tapIndex === 0) {
							this.logout()
						} else if (e.tapIndex === 1) {
							uni.navigateTo({
								url: '/subPage_mine/password'
							})
						} else if (e.tapIndex === 2) {
							uni.navigateTo({
								url: '/subPage_mine/index'
							})
						}
					}
				})
			},
			itemClick(e) {
				this.goPage('/subPage_notice/detail?id=' + e.id)
			},
			goMore() {
				this.goPage('/subPage_notice/index')
			},
		}
	}
</script>

<style lang="scss" scoped>
	.index {
		height: 100%;
		overflow: hidden;
		padding: 0 42upx;
		position: relative;

		.bg {
			width: 100%;
			height: 508upx;
			background: url('../../static/image/index-bg.png') no-repeat;
			background-size: 100%;
			position: absolute;
			top: 0;
			left: 0;
		}

		.top-wrapper {
			position: relative;
			//background-color: #018737;
			//height: 500upx;

			.status_bar {
				height: var(--status-bar-height);
				width: 100%;
				color: #fff;
			}

			.title-wrapper {
				color: #fff;
				display: flex;
				align-items: center;
				font-size: 38upx;

				.version {
					font-size: 28upx;
				}

				.logout {
					flex: 1;
					display: flex;
					align-items: center;
					justify-content: flex-end;
				}
			}
		}

		.schedule-box {
			height: 425upx;
			position: relative;
			margin-top: 40upx;

			.schedule-bg-box {
				position: absolute;
				left: -10rpx;
				top: 0;
				width: 675rpx;
				height: 55%;
				background-color: rgba(255, 255, 255, .2);
				border-radius: 28upx;
				transform: rotate(-4deg);
				z-index: 0;
			}

			.schedule-content-box {
				position: relative;
				z-index: 1;
				width: 100%;
				height: 100%;
				border-radius: 28upx;
				background-color: #ffffff;
				box-shadow: 0px 9rpx 14rpx rgba(115, 126, 222, 0.3);
				overflow: hidden;
				padding-top: 40upx;
			}

			.schedule-wrapper {
				display: flex;
				align-items: center;
				flex-wrap: wrap;
				margin-top: 20upx;

				.item {
					width: 25%;
					text-align: center;

					.number {
						color: red;
						font-size: 46upx;
						font-weight: bold;
						margin-bottom: 10upx;
					}

					.label {
						font-size: 28upx;
						color: #575A6E;
						margin-bottom: 40upx;
					}
				}
			}

			.notice-wrapper {
				position: absolute;
				width: 100%;
				bottom: 0;
				padding: 0 20upx;
				height: 80upx;
				background-color: #EDF2FF;
				display: flex;
				align-items: center;
				color: #000000;
				z-index: 1;
				box-sizing: border-box;
			}
		}

		.content-wrapper {
			position: relative;
		}

		.function-wrapper {
			background-color: #ffffff;
			border-radius: 20upx;
			margin: 20upx 0;
			overflow: hidden;
			box-shadow: 0 0 10rpx #dedede;

			.title-wrapper {
				display: flex;
				align-items: center;
				padding: 0 20upx;
				margin: 35rpx 0;

				.title {
					height: 36upx;
					line-height: 36upx;
					font-size: 36upx;
					color: #000000;
					padding-left: 15upx;
					//border-left: 10upx solid #018737;
				}
			}

			.item-wrapper {
				display: flex;
				align-items: center;
				flex-wrap: wrap;

				.item {
					width: 25%;
					text-align: center;

					.number {
						color: red;
						font-size: 32upx;
						font-weight: bold;
						margin-bottom: 15upx;
					}

					.label {
						font-size: 28upx;
						color: #434343;
						margin-bottom: 40upx;
						//margin: 15upx 0;
					}

					.icon {
						width: 100upx;
						height: 100upx;
						border-radius: 24upx;
						margin-bottom: 10upx;
					}
				}
			}
		}

		.time-info {
			margin-top: 25upx;
			color: #000000;
			padding: 26upx 0;

			.title {
				position: relative;
				font-size: 32upx;
				font-weight: bold;
				margin-bottom: 30upx;
				display: inline-block;
				color: #212121;

				.line {
					position: absolute;
					height: 16rpx;
					width: 100%;
					background-color: #CFDCFF;
					bottom: 2rpx;
					left: -5rpx;
					border-radius: 15rpx;
				}

				.text {
					position: relative;
					z-index: 1;
				}
			}



			.info {
				font-size: 26upx;
				margin-bottom: 10upx;
				display: flex;
				align-items: center;
				justify-content: space-between;
				color: #575A6E;
			}
		}

		.sjx-logo {
			width: 90%;
			margin-left: 5%;
			margin-bottom: -100upx;
		}

		.popup-wrapper {
			background-color: #ffffff;
			width: 600upx;
			height: 500upx;
			border-radius: 30upx;
			overflow: hidden;

			.popup-title-wrapper {
				text-align: center;
				position: relative;
				margin: 30upx 0;

				.title {
					font-size: 36upx;
				}

				.close {
					position: absolute;
					right: 30upx;
				}
			}

			.popup-content-wrapper {
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;

				.popup-item {
					height: 160upx;
					width: 520upx;
					border-radius: 10upx;
					border: 1upx solid #cecece;
					display: flex;
					align-items: center;
					justify-content: center;
					font-size: 32upx;
					color: #666666;
					margin-bottom: 30upx;
				}
			}
		}
	}
</style>